package com.wkw.jkyf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wkw.jkyf.common.ResultMapUtil;
import com.wkw.jkyf.pojo.Returnsupplier;


import com.wkw.jkyf.service.IReturnsupplierService;


import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Date;


//退货给供应商
@Controller
@RequestMapping(value = "/returnsupplier")
public class ReturnsupplierController {
    @Resource
    private IReturnsupplierService returnsupplierService;

    @RequestMapping
    public String login(){
        return "/returnsupplier";
    }

    /*
    分页查询退货给供应商列表
     */
    @RequestMapping("/returnsupplierQueryPage")
    @ResponseBody
    public Object supplierQueryPage(String param, @RequestParam(defaultValue = "1")int page, @RequestParam(defaultValue = "10")int pageSize){
        try{
            IPage<Returnsupplier> iPage = returnsupplierService.selectReturnsupplierPage(page,pageSize,param);
            return ResultMapUtil.getHashMapMysqlPage(iPage);
        }catch (Exception e){
            return ResultMapUtil.getHashException(e);
        }

    }
    //跳转到添加页面
    @RequestMapping(value = "/returnsupplierPage")
    public String supplierPage(){
        return "/returnsupplierPage";
    }

    //添加
    @RequestMapping(value = "/returnsupplierAdd")
    @ResponseBody
    public Object returnsupplierAdd(Returnsupplier returnsupplier){
        try {
            //    returnsupplier.setOperatetime(new Date());
            int i = returnsupplierService.addReturnsupplier(returnsupplier);
            return ResultMapUtil.getHashMapSave(i);
        } catch (Exception e) {
            return ResultMapUtil.getHashException(e);
        }

    }

    //按id查询
    @RequestMapping(value = "/returnsupplierQueryById")
    public String returnsupplierQueryById(@RequestParam(name = "id",required = true)Integer id, Model model) {
        Returnsupplier returnsupplier= returnsupplierService.queryReturnsupplierById(id);
        model.addAttribute("obj",returnsupplier);
        return "/returnsupplierPage";
    }

    //修改一个退货给供应商
    @RequestMapping(value = "/returnsupplierEdit")
    @ResponseBody
    public Object returnsupplierEdit(Returnsupplier returnsupplier) {
        try {
            int i= returnsupplierService.editReturnsupplier(returnsupplier);
            return ResultMapUtil.getHashMapSave(i);
        } catch (Exception e) {
            return  ResultMapUtil.getHashException(e);
        }
    }

    // 删除一个退货给供应商
    @RequestMapping(value = "/returnsupplierDelById")
    @ResponseBody
    public Object returnsupplierDelById(Integer id) {
        try {
            int i= returnsupplierService.deleteReturnsupplierById(id);
            return ResultMapUtil.getHashMapDel(i);
        } catch (Exception e) {
            return  ResultMapUtil.getHashException(e);
        }
    }

}
